package cj.web.yc.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.yc.domain.VideoOrder;

/**
 * 
 * @author 
 *
 */
@DAO
public interface VideoOrderDAO{
	
	@SQL("SELECT a.*,b.name as memberName FROM VideoOrder a left join member b on a.memberId=b.id WHERE a.deleteFlag=1 #if(:t.orderNo != null){ AND a.orderNo LIKE '%##(:t.orderNo)%' } #if(:t.status != null){ AND a.status=:t.status } #if(:t.payWay != null){ AND a.payWay=:t.payWay } ORDER BY a.updateAt DESC LIMIT :t.start,:t.length ")
    List<VideoOrder> query(@SQLParam("t") VideoOrder videoOrder);
	
	@SQL("SELECT count(1) FROM VideoOrder WHERE deleteFlag=1 #if(:t.orderNo != null){ AND orderNo LIKE '%##(:t.orderNo)%' } #if(:t.status != null){ AND status=:t.status } #if(:t.payWay != null){ AND payWay=:t.payWay } ")
    int querySize(@SQLParam("t") VideoOrder videoOrder);
    
    @SQL("select * from VideoOrder where id=:1")
    VideoOrder queryById(int id);
    
    @SQL("INSERT INTO VideoOrder (orderNo,memberId,price,status,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.orderNo,:t.memberId,:t.price,:t.status,1,now(),:t.createUser,now(),:t.updateUser) ")
    void create(@SQLParam("t") VideoOrder videoOrder);
    
    @ReturnGeneratedKeys
    @SQL("INSERT INTO VideoOrder (id,orderNo,memberId,price,status,deleteFlag,createAt,createUser,updateAt,updateUser,payWay) VALUES (:1,:2,:3,:4,:5,1,now(),:6,now(),:7,:8) ")
    int create(int id,String orderNo,int memberId,String price,int status,String createUser,String updateUser,int payWay);
	
	@SQL("UPDATE VideoOrder SET orderNo=:t.orderNo,memberId=:t.memberId,price=:t.price,status=:t.status,payWay=:t.payWay,payOrder=:t.payOrder,source=:t.source,updateAt=now(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") VideoOrder videoOrder);
    
    @SQL("UPDATE VideoOrder SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}